home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks95 / Aaron 1.0b3.sit / Aaron 1.0b3 / Aaron Source / CDEF and Patches / DrawTitle.c < prev    next >
Text File  |  1995-06-24  |  3KB  |  111 lines

  1. /*    Aaron © 1995 Gregory D. Landweber, ALL RIGHTS RESERVED    */
  2.     
  3. #include "CDEF.h"
  4. #include <Icons.h>
  5.  
  6. void GrayForeColor ( short index );
  7.  
  8. void DrawTitle ( GregInfo *theInfo, Boolean embossed, Boolean pushed, Boolean invert )
  9. {
  10.     FontInfo        fontProperties;
  11.     short            lineHeight, nLines, baseLine, firstChar, chIndex, lineLength, x, y;
  12.     RgnHandle        oldClip, newClip;
  13.     short            length;
  14.     StringPtr        theTitle;
  15.     unsigned char    newTitle[4];
  16.     Rect            theRect;
  17.     
  18.     if ( theInfo->newFolder ) {
  19.         theTitle = newTitle;
  20.         SetRect (&theRect,    theInfo->theRect.right - 27,
  21.                           ( theInfo->theRect.bottom + theInfo->theRect.top - 16 ) >> 1,
  22.                             theInfo->theRect.right - 11,
  23.                           ( theInfo->theRect.bottom + theInfo->theRect.top + 16 ) >> 1 );
  24.         if ( pushed && !theInfo->inActive )
  25.             OffsetRect (&theRect, 1, 1);
  26.         if ( theInfo->inActive )
  27.             PlotIconID (&theRect, atVerticalCenter, 1, -3999);
  28.         else
  29.             PlotIconID (&theRect, atVerticalCenter, 0, -3999);
  30.                     
  31.         *(long *)theTitle = ' New';
  32.         theTitle[0] = 3;
  33.     }
  34.     else {
  35.         HLock ( (Handle) theInfo->theControl );
  36.         theTitle = (*(theInfo->theControl))->contrlTitle;
  37.     }
  38.     
  39.     oldClip = NewRgn ();
  40.     GetClip (oldClip);
  41.     newClip = NewRgn ();
  42.     RectRgn( newClip, &(theInfo->theRect) );
  43.     SectRgn ( newClip, oldClip, newClip);
  44.     SetClip ( newClip );
  45.         
  46.     if ( embossed )
  47.         GrayForeColor ( 0x0F );
  48.     else
  49.         GrayForeColor ( 0x00 );
  50.     
  51.     if ( invert )
  52.         GrayForeColor ( 0x0F );
  53.         
  54.     if ( theInfo->inActive )
  55.         TextMode (grayishTextOr);
  56.     else
  57.         TextMode (srcOr);
  58.     
  59.     GetFontInfo( &fontProperties );
  60.     lineHeight = fontProperties.ascent + fontProperties.descent + fontProperties.leading;
  61.     length = theTitle[0];
  62.  
  63.     nLines = 1;
  64.     for (chIndex = 1; chIndex <= length; chIndex++)
  65.         if ( theTitle[chIndex] == 13 )
  66.             nLines += 1;
  67.  
  68.     baseLine = theInfo->theRect.bottom -
  69.                (theInfo->theRect.bottom + 1 - theInfo->theRect.top - nLines * lineHeight) / 2
  70.                  - fontProperties.leading - fontProperties.descent - (nLines - 1) * lineHeight;
  71.     if ( theInfo->pushButton && (lineHeight < 13) )
  72.         baseLine--;
  73.         
  74.     firstChar = 1;    
  75.     for (chIndex = 1; chIndex <= length; chIndex++)
  76.         if ( ( theTitle[chIndex] == 13 ) ||
  77.              ( chIndex == length )    ) {
  78.             lineLength = chIndex - firstChar;
  79.             if ( chIndex == length )
  80.                 lineLength += 1;
  81.             y = baseLine;
  82.             if ( !theInfo->pushButton )
  83.                 x = theInfo->theRect.left + ButtonLeft + ButtonSize + TitleGap;
  84.             else {
  85.                 if ( theInfo->newFolder )
  86.                     x = theInfo->theRect.left + 14;
  87.                 else
  88.                     x = ( theInfo->theRect.left + theInfo->theRect.right -
  89.                           TextWidth ( theTitle, firstChar, lineLength ) ) / 2;
  90.                 if ( pushed && !theInfo->inActive ) {
  91.                     x++;
  92.                     y++;
  93.                 }
  94.                 if ( embossed ) {
  95.                     x++;
  96.                     y++;
  97.                 }
  98.             }
  99.             MoveTo (x, y);
  100.             DrawText( theTitle, firstChar, lineLength);
  101.             baseLine  = baseLine + lineHeight;
  102.             firstChar = chIndex + 1;
  103.         }
  104.                 
  105.     SetClip (oldClip);
  106.     DisposeRgn (oldClip);
  107.     DisposeRgn (newClip);
  108.  
  109.     if ( !theInfo->newFolder )
  110.         HUnlock ( (Handle) theInfo->theControl );
  111. }